<?php
/** 
 * Created by RisingSun. 
 * User: MarkSpace 
 * Date: 20210822
 * Time: 11:05 
 */
namespace app\platform\model;

use app\platform\model\Model;
use Mscore\Core\Lang;
use Mscore\Core\Util\Util;

class Auth extends Model{

    private $error;
    private $success;
    private $header; //header值

    public function __construct()  
    {    
        $this->cross = config("app.cross");
        $this->header =get_all_headers();
        $this->header['language']=isset($this->header['language'])&&!empty($this->header['language'])?$this->header['language']:'default';
        Lang::init($this->header['language']);
        $this->success=Lang::get('Success');
        $this->error=Lang::get('Error');
    }

    /**
     *  用户检测
     * @param $token
    */
    public function isAuth(){
        $token=md5(config('file.acc').config('file.code'));
        header('Content-Type:application/json; charset=utf-8');
        if($this->cross['crossdomain']){
            foreach ($this->cross['crossinfo'] as $key => $value) {
                header($value);
            }
        }
        if (!isset($this->header['authorization'])||empty($this->header['authorization'])||$this->header['authorization']!=$token) {
            $this->error=Lang::get('Tokenempty');
            exit (json_encode($this->error));
        }
    }    

}